using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Text;

namespace Open.Data.Persistence.Tools
{
    public class DeploymentApplication: ApplicationContext
    {
        //Property variables
        private SelectAssemblyForm _selectAssembly;
        private SelectProviderForm _selectProvider;
        private SqlContextForm _contextForm;
        private SqlDeploymentForm _deploymentOptions;

        private int _step;

        public DeploymentApplication()
        {
            _selectAssembly = new SelectAssemblyForm();
            _selectProvider = new SelectProviderForm();
            _contextForm = new SqlContextForm();
            _deploymentOptions = new SqlDeploymentForm();
            _step = 1;
        }

        public SelectAssemblyForm SelectAssemblyForm
        {
            get 
            { 
                return _selectAssembly; 
            }
        }
        
        public SelectProviderForm SelectProviderForm
        {
            get 
            { 
                return _selectProvider; 
            }
        }
        
        public SqlContextForm SqlContextForm
        {
            get 
            { 
                return _contextForm; 
            }
        }
        

        public SqlDeploymentForm SqlDeploymentForm
        {
            get 
            { 
                return _deploymentOptions; 
            }
        }

        public int Step
        {
            get
            {
                return _step;
            }
            set
            {
                _step = value;
            }
        }

        public void ProcessStep()
        {
            WizardBaseForm form = null;
            //Show the forms and get data
            if (Step == 1) form = SelectAssemblyForm;
            if (Step == 2) form = SelectProviderForm;
            if (Step == 3) form = SqlContextForm;
            if (Step == 4)
            {
                SqlDeploymentForm.Context = SqlContextForm.Context;
                SqlDeploymentForm.Assembly = SelectAssemblyForm.Assembly;
                form = SqlDeploymentForm;
            }

            //Can occasionally throw an MDA exception which has been disabled
            if (form != null && !form.Disposing) form.ShowDialog();

            if (form.WizardResult == WizardResult.Cancel) Step = 0;
            else if (form.WizardResult == WizardResult.Previous) Step -= 1;
            else if (form.WizardResult == WizardResult.Next) Step += 1;
        }
    }
}
